package tedu.boot412.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import tedu.boot412.entity.Product;
import tedu.boot412.mapper.ProductMapper;

import java.util.List;

@RestController
public class ProductController {
    @Autowired
    ProductMapper productMapper;

    @RequestMapping("/insert")
    public void insert(@RequestBody Product product){
        System.out.println("product = " + product);
        productMapper.insert(product);
    }

    @RequestMapping("/select")
    public List<Product> select(){
        return productMapper.select();
    }

    @RequestMapping("/delete")
    public void deleteById(int id){
        System.out.println("id = " + id);
        productMapper.deleteById(id);
    }

    @RequestMapping("/selectById")
    public Product selectById(int id){
        return productMapper.selectById(id);
    }

    @RequestMapping("/update")
    public void update(@RequestBody Product product){
        System.out.println("product = " + product);
        productMapper.update(product);
    }
}
